
/******************************************************************************
 *
 *	PROJECT: Flynax Classifieds Software
 *	VERSION: 4.0
 *	LISENSE: FL87MPRYOA0R - http://www.flynax.com/license-agreement.html
 *	PRODUCT: Auto Classifieds
 *	DOMAIN: www.siyaradiali.com
 *	FILE: LIB.JS
 *
 *	This script is a commercial software and any kind of using it must be 
 *	coordinate with Flynax Owners Team and be agree to Flynax License Agreement
 *
 *	This block may not be removed from this file or any other files with out 
 *	permission of Flynax respective owners.
 *
 *	Copyrights Flynax Classifieds Software | 2012
 *	http://www.flynax.com/
 *
 ******************************************************************************/

var wf_days = new Array();
wf_days['sun'] = 0;
wf_days['mon'] = 1;
wf_days['tue'] = 2;
wf_days['wed'] = 3;
wf_days['thu'] = 4;
wf_days['fri'] = 5;
wf_days['sat'] = 6;

$(document).ready(function(){
	if ( wf_use_geo && !wf_sess_geo )
	{
		$.getJSON(wf_request,
			{
				mode: 'query',
				query: wf_ipgeo
			},
			function(response){
				if ( response && response['data']['woeid'] )
				{
					wf_la_woeid = response['data']['woeid'];
					
					if ( wf_la_woeid )
					{
						wf_getContent(wf_la_woeid);
						xajax_saveSessWoeid(wf_la_woeid);
					}
					else
					{
						$('#wf_area_loading').html(wf_la_not_found);
						return false;
					}
				}
				else
				{
					$('#wf_area_loading').html(wf_la_not_found);
					return false;
				}
			}
		);
	}
	else if ( wf_use_geo && wf_sess_geo )
	{
		wf_getContent(wf_sess_geo);
	}
	else
	{
		wf_getContent(wf_woeid);
	}
});

var wf_getContent = function(wf_woeid){
	$.getJSON(wf_request,
		{
			mode: 'wf',
			w: wf_woeid,
			u: wf_unit == 'Celsius' ? 'c' : 'f'
		},
		function(response){
			if ( !response['data']['location'] )
			{
				$('#wf_block_loading').html(wf_not_found);
				return false;
			}
			
			var data = response['data'];
			var unit = wf_unit == 'Celsius' ? 'C' : 'F';
			unit = '&deg;'+ unit;
			
			/* build title */
			var location = data['location'];
			
			if ( location['region'] != '' && location['city'] != '' )
			{
				var title = location['city'] +", "+ location['region'];
			}
			else
			{
				var title = location['city'] +", "+ location['country'];
			}
			$('#wf_block_loc').html(title);
			
			/* build current conditions */
			var cur_cond = data['condition'];
			var conditions = wf_conditions[cur_cond['code']] +', <b>'+ cur_cond['temp'] +'</b> '+ unit;
			$('#wf_block_cond div.cur_cond').html(conditions);
			
			/* set wether sign */
			if ( cur_cond['code'] != '3200' )
			{
				var image = '<img alt="'+ wf_conditions[cur_cond['code']] +'" title="'+ wf_conditions[cur_cond['code']] +'" src="'+ wf_url +'signs/'+ cur_cond['code'] +'.png" />';
				$('#wf_block_cond div.cur_img').html(image);
			}
			
			/* set forecast */
			var forecast = data['forecast'];
			var forecast_out = '<table style="font-size: 12px;">';
			
			for ( var i=0; i<forecast.length; i++ )
			{
				forecast_out += '<tr> \
									<td valign="top" style="width: 30px;text-transform: capitalize;" title="'+ forecast[i]['date'] +'">'+ $.datepicker.regional[wf_lang_code].dayNamesShort[wf_days[forecast[i]['day'].toLowerCase()]] +'</td> \
									<td valign="top"> \
										<b>'+ wf_conditions[forecast[i]['code']] +'</b> \
										<div style="font-size: 11px;padding: 0 0 5px 0;"> \
										'+wf_high+' '+ forecast[i]['high'] +' '+ unit +', '+wf_low+' '+ forecast[i]['low'] +' '+ unit +' \
										</div> \
									</td> \
								</tr>';
			}
			forecast_out += '</table>';
			
			$('#wf_block_forecast').html(forecast_out);
			
			/* open block */
			$('#wf_block_loading').fadeOut('normal', function(){
				$('#wf_block_data').fadeIn('normal');
			});
		}
	);
}